package belf.migrate.api.util;

import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor;

import java.util.List;

public class SQLTranslator {
    public static void main(String[] args) {

        // MySQL 创建视图语句
        String mysqlCreateViewSQL = "";

        // 解析 MySQL 创建视图语句
        MySqlStatementParser parser = new MySqlStatementParser(mysqlCreateViewSQL);
        List<SQLStatement> statementList = parser.parseStatementList();
        SQLCreateViewStatement mysqlCreateViewStatement = (SQLCreateViewStatement) statementList.get(0);

        // 使用 Druid 生成达梦数据库的 SQL 语句
        StringBuilder out = new StringBuilder();
        OracleOutputVisitor oracleOutputVisitor = new OracleOutputVisitor(out);
        mysqlCreateViewStatement.accept(oracleOutputVisitor);
        String dmCreateViewSQL = out.toString();

        // 打印达梦数据库的创建视图语句
        System.out.println("达梦数据库的创建视图语句:");
        System.out.println(dmCreateViewSQL);
    }
}
